{% extends "oa/base.html" %}
{% load i18n static %}
{% block title %} 原料库存明细 {% endblock %}
{% block header_nav %}{% endblock %}
{% block this_css %}
    <style>
        tbody > tr > td {
            white-space: nowrap
        }
    </style>
{% endblock %}
{% block content %}
    <section class="panel">
        <div class="panel-body">
            <form method="get" action="{{ request.path }}" class="form-inline">
                <div class="form-group">
                    <label for="q">搜索:</label>
                    <input type="text" class="form-control" name="q" value="{{ request.GET.q }}" id="q">
                </div>
                <div class="form-group">
                    <label for="material_category_id">种类:</label>
                    <select name="material_category_id" id="material_category_id" class="form-control">
                        <option value="">-----</option>
                        {% for mc in material_categories %}
                        {% ifequal mc.pk|escape request.GET.material_category_id %}
                        <option value="{{ mc.pk }}" selected>{{ mc.name }}</option>
                        {% else %}
                        <option value="{{ mc.pk }}">{{ mc.name }}</option>
                        {% endifequal %}
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group">
                    <label for="category_type">归类:</label>
                    <select name="category_type" id="category_type" class="form-control">
                        <option value="">-----</option>
                        {% for k, v in category_types.items %}
                        {% ifequal k|escape request.GET.category_type %}
                        <option value="{{ k }}" selected>{{ v }}</option>
                        {% else %}
                        <option value="{{ k }}">{{ v }}</option>
                        {% endifequal %}
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group">
                    <label for="date_start">开始日期:</label>
                    <input type="text" class="form-control" name="date_start" value="{{ request.GET.date_start }}"
                           id="date_start" placeholder="yyyy-mm-dd" data-date-format="yyyy-mm-dd">
                </div>
                <div class="form-group">
                    <label for="date_end">截止日期:</label>
                    <input type="text" class="form-control" name="date_end" value="{{ request.GET.date_end }}"
                           id="date_end" placeholder="yyyy-mm-dd" data-date-format="yyyy-mm-dd">
                </div>
                <button type="submit" class="btn btn-info">重新统计</button>
                <a target="_blank"
                   href="?excel=1&date_start={{ request.GET.date_start }}&date_end={{ request.GET.date_end }}&q={{ request.GET.q }}&material_category_id={{ request.GET.material_category_id }}&category_type={{ request.GET.category_type }}">
                    <span type="submit" class="btn btn-default">导出EXCEL</span>
                </a>
            </form>
        </div>
    </section>
    <section class="panel">
        <div class="panel-body table-responsive">
            <table class="table table-striped table-bordered table-responsive">
                <thead>
                    <tr>
                        <th colspan="{% if request.GET.date_start and request.GET.date_end %}11{% else %}10{% endif %}"><h3>原料库存明细</h3></th>{% if perms.oa.add_moneyinout %}
                        <th class="text-right">{{ total_assets|floatformat:'2' }}</th>{% endif %}
                    </tr>
                    <tr>
                        <th>ID</th>
                        <th>原料类别</th>
                        <th>物料编码</th>
                        <th>原料名称</th>
                        <th>批次号</th>
                        <th>包装规格</th>
                        <th>单位</th>{% if request.GET.date_start and request.GET.date_end %}
                        <th class="text-right">期初数量</th>
                        <th class="text-right">期末数量</th>{% else %}
                        <th class="text-right">当前数量</th>{% endif %}
                        <th class="text-right">采购单价/元</th>
                        <th class="text-right">单位成本/元</th>
                        <th class="text-right">结存金额/元</th>
                    </tr>
                </thead>
                <tbody>
                    {% for row in object_list %}
                    <tr>
                        <td>{{ row.pk }}</td>
                        <td>{{ row.material__material_category__name }}</td>
                        <td>{{ row.material__code }}</td>
                        <td>{{ row.material__name }}</td>
                        <td>{{ row.code }}</td>
                        <td>{{ row.package_unit__display|default_if_none:'' }}</td>
                        <td>{{ row.package_unit__unit|default_if_none:'' }}</td>{% if request.GET.date_start and request.GET.date_end %}
                        <td class="text-right">{{ row.mbs_start|floatformat:'3' }}</td>
                        <td class="text-right">{{ row.mbs_end|floatformat:'3' }}</td>{% else %}
                        <td class="text-right">{{ row.left_amount|floatformat:'3' }}</td>{% endif %}
                        <td class="text-right">{{ row.unit_price|floatformat:'4' }}</td>
                        <td class="text-right">{{ row.unit_cost|floatformat:'4' }}</td>
                        <td class="text-right">{{ row.assets|floatformat:'2' }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            <div class="text-right">
                {% include 'pagination.html' %}
            </div>
        </div>
    </section>
{% endblock %}
